package com.cn.service.server.Report.Impl;

import com.cn.bean.pojo.TechnologicalStandard.GrindingProcessStandardMain;
import com.cn.bean.pojo.bc.MaterList;
import com.cn.bean.pojo.bc.UseDefinition;
import com.cn.bean.vo.Report.PartsList;
import com.cn.mapper.dao.db1.bc.MaterialQualityDao;
import com.cn.mapper.dao.db1.bc.PurposesDao;
import com.cn.mapper.dao.db5.Report.PartsListDao;
import com.cn.service.server.Report.PartsListServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PartsListServerImpl implements PartsListServer {

    private final PartsListDao partsListDao;
    private final PurposesDao purposesDao;
    //    private final Mate mate;
    private final MaterialQualityDao mate;

    @Autowired(required = false)
    public PartsListServerImpl(PartsListDao partsListDao, PurposesDao purposesDao, MaterialQualityDao mate) {
        this.purposesDao = purposesDao;
        this.mate = mate;
        this.partsListDao = partsListDao;
    }

    @Override
    public List<PartsList> selectItemPartsList(int limit, int page,String structureName, String componentName, String consumableCategoryName,  String specification, String model, String processName) {

        List<PartsList> selectItemPartsList = partsListDao.selectItemPartsList(limit, page,structureName,componentName,consumableCategoryName,specification,model,processName);


        for (PartsList gr : selectItemPartsList) {
            int productPurpose = gr.getProductPurpose();
            if (productPurpose != 0) {
                List<UseDefinition> useDefinitions = purposesDao.selectUseDefinitionId(gr.getProductPurpose());
                UseDefinition useDefinition = useDefinitions.get(0);
                gr.setProductPurposeName(useDefinition.getYtmc());

            }
            int material = gr.getMaterial();
            if (material != 0) {
                List<MaterList> materLists = mate.selectUseDefinitionId(gr.getMaterial());
                MaterList mater = materLists.get(0);
                gr.setMaterialName(mater.getYtmc());
            }
        }

        return selectItemPartsList;
    }

}
